package campeonatofutebol.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.util.Log;
import campeonatofutebol.util.Constantes;

public class RepositorioDeDados {
	
	private static RepositorioDeDados repositorio;
	private Map<Time, List<String>> timesComFeeds;
	private ArrayList<String> grupos, timesFavoritados;
	private Map<String, List<String>> campeonatosFeeds;
	private Classificacao tabelaBrasileiraoA;
	private Classificacao tabelaBrasileiraoB;
	private List<Jogo> jogosDaSemana;
	
	private RepositorioDeDados(){
		grupos = new ArrayList<String>();
		timesComFeeds = new HashMap<Time, List<String>>();
		campeonatosFeeds = new HashMap<String, List<String>>();
		timesFavoritados = new ArrayList<String>();
		jogosDaSemana = new ArrayList<Jogo>();
		inicializaTimesComFeed();
		inicializaClassificacoes();
		inicializaGrupos();
		inicializaCampeonatosFeeds();
		//inicializaTimesFavoritados();
	}
	
	public static RepositorioDeDados getInstance(){
		return  repositorio == null ? repositorio = new RepositorioDeDados(): repositorio;
	}
	
	public Classificacao getClassificaoBrasileiraoSerieA(){
		return this.tabelaBrasileiraoA;
	}
	
	public Classificacao getClassificaoBrasileiraoSerieB(){
		return this.tabelaBrasileiraoB;
	}
	
	public List<Jogo> getJogosDaSemana(){
		return this.jogosDaSemana;
	}
	
	public List<Time> getTimes() {
		 List<Time> times = new ArrayList<Time>(timesComFeeds.keySet());
		 Collections.sort(times);
		 return times;
	}
	
	public Map<Time, List<String>> getTimesComFeeds() {
		return timesComFeeds;
	}
	
	public ArrayList<String> getGrupos() {
		return grupos;
	}
	
	public Map<String, List<String>> getCampComFeeds() {
		return campeonatosFeeds;
	}
	
	public List<String> getCampeonatos(){
		List<String> campeonatos = new ArrayList<String>(campeonatosFeeds.keySet());
		return campeonatos;
	}
	
	public List<String> getFavoritos() {
		return timesFavoritados;
	}
	
	public void favoritaTime(String nomeTime) {
		for(Time t : timesComFeeds.keySet()) {
			if(t.getNome().equals(nomeTime)) {
				t.setStatusFavorito();
			}
		}
	}
	
	private void inicializaTimesComFeed(){
		List<String> feeds1 = new ArrayList<String>();
		feeds1.add(Constantes.ATLET_MG_FEED_GE);
		feeds1.add(Constantes.ATLET_MG_FEED_GZ);
		timesComFeeds.put(new Time("Atletico MG"), feeds1 );
		
		List<String> feeds2 = new ArrayList<String>();
		feeds2.add(Constantes.ATLET_PR_FEED_GE);
		feeds2.add(Constantes.ATLET_PR_FEED_GZ);		
		timesComFeeds.put(new Time("Atlético PR"),feeds2);
		
		List<String> feeds3 = new ArrayList<String>();
		feeds3.add(Constantes.AVAI_FEED_GE);
		feeds3.add(Constantes.AVAI_FEED_GZ);
		timesComFeeds.put(new Time("Avaí"), feeds3 );
		
		List<String> feeds4 = new ArrayList<String>();
		feeds4.add(Constantes.BAHIA_FEED_GE);
		feeds4.add(Constantes.BAHIA_FEED_GZ);
		timesComFeeds.put(new Time("Bahia"), feeds4);
		
		List<String> feeds5 = new ArrayList<String>();
		feeds5.add(Constantes.BOTAFOGO_FEED_GE);
		feeds5.add(Constantes.BOTAFOGO_FEED_GZ);
		timesComFeeds.put(new Time("Botafogo"), feeds5);
		
		List<String> feeds6 = new ArrayList<String>();
		feeds6.add(Constantes.CORINTH_FEED_GE);
		feeds6.add(Constantes.CORINTH_FEED_GZ);
		timesComFeeds.put(new Time("Corinthians"), feeds6);
		
		List<String> feeds7 = new ArrayList<String>();
		feeds7.add(Constantes.CORITIBA_FEED_GE);
		feeds7.add(Constantes.CORITIBA_FEED_GZ);
		timesComFeeds.put(new Time("Coritiba"), feeds7);
		
		List<String> feeds8 = new ArrayList<String>();
		feeds8.add(Constantes.CRUZEIRO_FEED_GE);
		feeds8.add(Constantes.CRUZEIRO_FEED_GZ);
		timesComFeeds.put(new Time("Cruzeiro"),feeds8);
		
		List<String> feeds9 = new ArrayList<String>();
		feeds9.add(Constantes.FIGUEIR_FEED_GE);
		feeds9.add(Constantes.FIGUEIR_FEED_GZ);
		timesComFeeds.put(new Time("Figueirense"), feeds9);
		
		List<String> feeds10 = new ArrayList<String>();
		feeds10.add(Constantes.FLA_FEED_GE);
		feeds10.add(Constantes.FLA_FEED_GZ);
		timesComFeeds.put(new Time("Flamengo"), feeds10);
		
		List<String> feeds11 = new ArrayList<String>();
		feeds11.add(Constantes.FLU_FEED_GE);
		feeds11.add(Constantes.FLU_FEED_GZ);
		timesComFeeds.put(new Time("Fluminense"), feeds11);
		
		List<String> feeds12 = new ArrayList<String>();
		feeds12.add(Constantes.GOI_FEED_GE);
		feeds12.add(Constantes.GOI_FEED_GZ);
		timesComFeeds.put(new Time("Goiás"), feeds12);
		
		List<String> feeds13 = new ArrayList<String>();
		feeds13.add(Constantes.GREMIO_FEED_GE);
		feeds13.add(Constantes.GREMIO_FEED_GZ);
		timesComFeeds.put(new Time("Grêmio"), feeds13);
		
		List<String> feeds14 = new ArrayList<String>();
		feeds14.add(Constantes.INTER_FEED_GE);
		feeds14.add(Constantes.INTER_FEED_GZ);
		timesComFeeds.put(new Time("Internacional"), feeds14);
		
		List<String> feeds15 = new ArrayList<String>();
		feeds15.add(Constantes.NAUT_FEED_GE);
		feeds15.add(Constantes.NAUT_FEED_GZ);
		timesComFeeds.put(new Time("Náutico"), feeds15);
		
		List<String> feeds16 = new ArrayList<String>();
		feeds16.add(Constantes.PALM_FEED_GE);
		feeds16.add(Constantes.PALM_FEED_GZ);
		timesComFeeds.put(new Time("Palmeiras"), feeds16);
		
		List<String> feeds17 = new ArrayList<String>();
		feeds17.add(Constantes.PAR_FEED_GE);
		feeds17.add(Constantes.PAR_FEED_GZ);
		timesComFeeds.put(new Time("Paraná"), feeds17);

		List<String> feeds18 = new ArrayList<String>();
		feeds18.add(Constantes.PORTUG_FEED_GE);
		feeds18.add(Constantes.PORTUG_FEED_GZ);
		timesComFeeds.put(new Time("Portuguesa"), feeds18);
		
		List<String> feeds19 = new ArrayList<String>();
		feeds19.add(Constantes.SANTOS_FEED_GE);
		feeds19.add(Constantes.SANTOS_FEED_GZ);
		timesComFeeds.put(new Time("Santos"), feeds19);
		
		List<String> feeds20 = new ArrayList<String>();
		feeds20.add(Constantes.SPORT_FEED_GE);
		feeds20.add(Constantes.SPORT_FEED_GZ);
		timesComFeeds.put(new Time("Sport"), feeds20);

		List<String> feeds21 = new ArrayList<String>();
		feeds21.add(Constantes.SP_FEED_GE);
		feeds21.add(Constantes.SP_FEED_GZ);
		timesComFeeds.put(new Time("São Paulo"), feeds21);
		
		List<String> feeds22 = new ArrayList<String>();
		feeds22.add(Constantes.TREZE_FEED);
		timesComFeeds.put(new Time("Treze"), feeds22);
		
		List<String> feeds23 = new ArrayList<String>();
		feeds23.add(Constantes.VASCO_FEED_GE);
		feeds23.add(Constantes.VASCO_FEED_GZ);
		timesComFeeds.put(new Time("Vasco"), feeds23);
		
		List<String> feeds24 = new ArrayList<String>();
		feeds24.add(Constantes.VITORIA_FEED_GE);
		feeds24.add(Constantes.VITORIA_FEED_GZ);
		timesComFeeds.put(new Time("Vitória"), feeds24);
		Log.w("feeds10", feeds1.get(0));
		Log.w("feeds11", feeds1.get(1));
	
	}
	
	private void inicializaClassificacoes(){
		tabelaBrasileiraoA = new Classificacao(Constantes.BRAS_SERIEA, Constantes.UOL_TAB_SERIEA);
		tabelaBrasileiraoB = new Classificacao(Constantes.BRAS_SERIEB, Constantes.UOL_TAB_SERIEB);
	}
	
	private void inicializaCampeonatosFeeds(){
		List<String> feeds1 = new ArrayList<String>();
		feeds1.add(Constantes.BRAS_SERIEA_FEED);
		campeonatosFeeds.put(Constantes.BRAS_SERIEA, feeds1);
		List<String> feeds2 = new ArrayList<String>();
		feeds2.add(Constantes.BRAS_SERIEB_FEED);
		campeonatosFeeds.put(Constantes.BRAS_SERIEB, feeds2);
		List<String> feeds3 = new ArrayList<String>();
		feeds3.add(Constantes.BRAS_SERIEC_FEED);
		campeonatosFeeds.put(Constantes.BRAS_SERIEC, feeds3);
	}
	
	private void inicializaGrupos(){
		grupos.add("Times");
		grupos.add(Constantes.BRAS_SERIEA);
		grupos.add(Constantes.BRAS_SERIEB);
		grupos.add(Constantes.BRAS_SERIEC);
		grupos.add("Favoritos");
		grupos.add("Jogos da Semana");
		grupos.add("Notificações");
	}
	
	
	
}